package com.unknowpupil.design.strategy;

/**
 * @Description: <p>
 * 上下文类，负责和具体的策略交互
 * 这样的话，具体算法和直接客户端调用分离。死的算法可以独立于客户端独立变化
 * </p>
 * @Author: <a> w10g </a>
 * @CreateDate: Create in 2020/4/28 15:17
 * @Classname: Context
 * @Version: 1.0
 */
public class Context {
    /**
     * 当前算法采用对象
     */
    private Strategy strategy;

    /**
     * 可以通过构造器注入
     * @param strategy
     */
    public Context(Strategy strategy) {
        this.strategy = strategy;
    }
    /**
     * 可以通过Set注入
     * @param strategy
     */
    public void setStrategy(Strategy strategy) {
        this.strategy = strategy;
    }

    public void printPrice(double s){
        System.out.println("您该报价:" +strategy.getPrice(s));
    }
}
